package cn.com.ddapp.ddm.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.api.OKUtilAPI;
import cn.com.ddapp.ddm.bean.HomeBean;
import cn.com.ddapp.ddm.bean.mine.CircleView;
import cn.com.ddapp.ddm.util.TDevice;
import cn.com.ddapp.ddm.widget.CircleImageView;

/**
 * Created by Administrator on 2016/8/18 0018.
 */
public class BrandRevelryAdapter extends RecyclerView.Adapter<BrandRevelryAdapter.MyHolder> {
    private Context context;
    private List<HomeBean.BrandListBean> brandListBeen;
    private LayoutInflater inflater;

    public BrandRevelryAdapter(Context context, List<HomeBean.BrandListBean> brandListBeen) {
        this.context = context;
        this.brandListBeen=brandListBeen;
        inflater=LayoutInflater.from(context);
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = inflater.inflate(R.layout.item_recycler_goods, parent, false);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, final int position) {
        int width=(int)(TDevice.getScreenWidth()-40)/3;
        RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(width,width);
        holder.recyclerImag.setLayoutParams(params);
        Glide.with(context).load(OKUtilAPI.imgBaseUrl+brandListBeen.get(position).getHeadImg()).into(holder.recyclerImag);
        holder.recyclerText.setText(brandListBeen.get(position).getName());

        holder.llRoot.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(v, position);
                }
            }
        });

        holder.llRoot.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemLongClick(v, position);
                }
                return true;
            }
        });

    }
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }
    OnItemClickListener onItemClickListener;

    public interface OnItemClickListener {
        void onItemClick(View v, int position);

        void onItemLongClick(View v, int position);
    }
    @Override
    public int getItemCount() {
        return brandListBeen.size();
    }

    class MyHolder extends RecyclerView.ViewHolder{
        private ImageView recyclerImag;
        private TextView recyclerText;
        private RelativeLayout llRoot;
        public MyHolder(View itemView) {
            super(itemView);

            recyclerImag = ((ImageView) itemView.findViewById(R.id.recyclerImag));
            recyclerText = ((TextView) itemView.findViewById(R.id.recyclerText));
            llRoot = ((RelativeLayout) itemView.findViewById(R.id.llRoot));

        }
    }
}
